class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  before_filter :configure_permitted_parameters, if: :devise_controller?

  ROLE_SET=%w( admin hr editor)

  include ApplicationHelper
  before_filter :init

  def init
    set_local
    count_unread_notification
  end
  # 设置所有环境为汉语
  def set_local
    I18n.locale= params[:locale]||I18n.default_locale
  end

  def fresh_when(opts={})
    # 写死固有影响界面的元素(当前用户)
    # 短路或赋值

    opts[:etag]||=[]
    # 保证etag参数是array类型
    opts[:etag]=[opts[:etag]] if !opts[:etag].is_a?(Array)
    #加入页面上直接调用的信息用于组合etag
    #用户信息
    opts[:etag] << current_user
    #所有Etag保持一天
    opts[:etag]=Date.current

    super(opts)

  end

protected
  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:name,:QQ,:telephone,:company,:self_introduce,:password,:password_confirmation,:current_password)}
    devise_parameter_sanitizer.for(:account_update) {|u| u.permit(:name,:QQ,:telephone,:company,:self_introduce,:password,:password_confirmation,:current_password)}

  end

end
